package com.raysdata.smartcity.flow.activiti.listeners;

import org.activiti.engine.delegate.DelegateTask;
import org.activiti.engine.delegate.TaskListener;
import org.activiti.engine.task.IdentityLink;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.Set;

/**
 * Created by liux on 2017/3/6.
 */

@Component
public class TaskUserListener implements TaskListener {
    public void notify(DelegateTask delegateTask) {

        // 获取当前节点定义分组, 并进行删除, 根据节点分组中的人员进行派发.
       /* Set<IdentityLink> identityLinkSet = delegateTask.getCandidates();
        for (IdentityLink il : identityLinkSet) {
            delegateTask.deleteCandidateGroup(il.getGroupId());
        }*/

       //获取环节处理人
        //String[] users = delegateTask.getVariable(delegateTask.getTaskDefinitionKey()+"users").toString().split(",");
        String[] users = delegateTask.getVariable("approveUsers").toString().split(",");
        if (users.length > 1) {
            delegateTask.addCandidateUsers(Arrays.asList(users));
        } else {
            delegateTask.setAssignee(users[0]);
        }
    }
}
